class SingersController < ApplicationController
  before_action :exception_stb, only: [:show]

  def index
    @singer_tags = SingerTag.ordered.each_slice(4)
  end

  def show
    @singer = Singer.includes(:songs).find(params[:id])
    @fav_singers = current_user.singers
    @picks = current_user.picklist.songs.pluck(:id)
    @favs = current_user.song_fav.songs.pluck(:id)
  end

  def choose
    params[:singer_tag_id] ||= 1
    @singer_tags = SingerTag.ordered
    @singer_tag_max_pages, @singer_tag_init_pages = Singer.init_and_max_pages
    # 按照 is_shown排序, 让有头像的排在前面
    @singers = Singer.where(singer_tag: params[:singer_tag_id]).order(is_shown: :desc, id: :asc).page(params[:page] || 1).per(16).each_slice(8)

    respond_to do |format|
      format.html
      format.js
    end
  end
end
